package com.vhall.component.service.room.event.handler.document;

import com.vhall.component.service.room.event.handler.AbstractEventHandler;
import com.vhall.component.service.room.event.handler.EventHandlerType;
import com.vhall.component.service.room.event.handler.RedirectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

import static com.vhall.component.service.room.event.EventConstant.DOCUMENT_TRANS_CONVERSION_PROCESS;

/**
 * 文档转码进度回调通知
 *
 * @author jingwen.li
 * @date 2023/2/16
 */
@Slf4j
@Component
@EventHandlerType(DOCUMENT_TRANS_CONVERSION_PROCESS)
public class DocumentTransProcessEventHandler extends AbstractEventHandler {
    @Autowired
    private RedirectUtil redirectUtil;
    @Value("${old.callback.document.url}")
    private String callbackUrl;
    @Override
    public void handle(Map<String, Object> callBack) {
        redirectUtil.redirect(callbackUrl, callBack);
//        event	string	是	document/trans-over
//        refer	string	是	vhall
//        time	string	是	回调时间戳
//        document_id	string	是	文档ID
//        trans_status	int	是	转码状态
//        converted_type	string	是	文档转换类型，only_static只转静态，only_h5只转h5，only_all全转
//        converted_process	string	是	转码进度,从10%到90%,完成派发转码完成事件
//        signature	string	是	回调签名
        log.info("收到文档转码进度事件：{}, 文档：{},转码状态：{},进度：{}", DOCUMENT_TRANS_CONVERSION_PROCESS,
                callBack.get("document_id"),
                callBack.get("trans_status"),
                callBack.get("converted_process"));

    }
}
